package common

import (
	"github.com/opentracing/opentracing-go"
	zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
	"github.com/openzipkin/zipkin-go"
	"github.com/openzipkin/zipkin-go/reporter"
	zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
)

var (
	OpTracer opentracing.Tracer
)

func InitOpTracer(serviceName string, port string) (reporter reporter.Reporter, err error) {
	reporter = zipkinhttp.NewReporter("http://127.0.0.1:9411/api/v2/spans")
	//defer reporter.Close()

	zEP, _ := zipkin.NewEndpoint("order_server", "8084")
	zipkinTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(zEP))
	if err != nil {
		Logger.Println(err)
		return
	}
	OpTracer = zipkinot.Wrap(zipkinTracer)
	return
}
